import 'package:flutter/material.dart';
import 'package:flutter_nft/page/home/home_index_pro.dart';
import 'package:flutter_nft/page/message/message_index.dart';
import 'package:flutter_nft/page/my/my_index_pro.dart';
import 'package:flutter_nft/provider/LoginProvider.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

class TkVideo {
  late int id;
  late String name;
  late String desc;
  late String imageUrl;
  late String videoUrl;
  late int dFlag;
  late String createTime;
  late String updateTime;

  TkVideo.name(this.id, this.name, this.desc, this.imageUrl, this.videoUrl,
      this.dFlag, this.createTime, this.updateTime);
}

class ListViewProTwo {
  late int id;
  late String name;
  late int icon;

  ListViewProTwo(this.id, this.name, this.icon);
}

class TabbarView extends StatefulWidget {
  List<Widget> tabsbottom = [
    HomeIndexProTwo(),
    //FindIndex(),
    MessageIndex(),
    MyIndexPro()
  ];

  @override
  _TabbarViewState createState() => _TabbarViewState();
}

class _TabbarViewState extends State<TabbarView> {

  bool phone = false;

  List<ListViewProTwo> mapList = [
    new ListViewProTwo(0, "首页", 0xe7eb),
    // new ListViewProTwo(1, "发现", 0xe720),
    new ListViewProTwo(1, "产品", 0xe711),
    new ListViewProTwo(2, "我的", 0xe62f),
  ];

  int _index = 0;

  @override
  void initState() {

    // TODO: implement initState
    super.initState();

    print("打印获取到的状态");
    print((context.read<LoginProvider>().getUserName().length).toString());
    if(context.read<LoginProvider>().getIsLogin()){
      setState(() {
        phone = true;
      });
    }


    getShape();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

  getShape()async{
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String? resultPhone = prefs.get("phone") as String?;
    print("打印缓存...");
    print(resultPhone);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        // appBar: AppBar(
        //   title: Text("底部选项卡"),
        //   centerTitle: true,
        // ),
        body: Stack(
      children: [
        widget.tabsbottom[_index],
        Positioned(
          bottom: 0,
          child: Container(
            color: Colors.black,
            width: MediaQuery.of(context).size.width,
            height: 60,
            child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: mapList
                    .map(
                      (e) => InkWell(
                        onTap: () {
                          setState(() {
                            _index = e.id;
                          });
                          print(e.id.toString());
                        },
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            SizedBox(
                              height: 5,
                            ),
                            e.id == _index
                                ? Container(
                                    //color: Colors.orange,
                                    width: 28,
                                    height: 28,
                                    child: Icon(
                                      IconData(
                                          e.id == 0
                                              ? 0xe7eb
                                              : e.id == 1
                                                  ? 0xe711
                                                  : 0xe62f,
                                          fontFamily: "Schyler"),
                                      //Icons.add,
                                      size: 22,
                                      color: Colors.black,
                                    ),
                                    decoration: BoxDecoration(boxShadow: [
                                      BoxShadow(
                                          offset: Offset(1, 1),
                                          blurRadius: 5,
                                          color: Colors.white)
                                    ], borderRadius: BorderRadius.circular(10)),
                                  )
                                : Container(
                                    //color: Colors.orange,
                                    width: 28,
                                    height: 28,
                                    child: Icon(
                                      IconData(
                                          e.id == 0
                                              ? 0xe7eb
                                              : e.id == 1
                                                  ? 0xe711
                                                  : 0xe62f,
                                          fontFamily: "Schyler"),
                                      //Icons.add,
                                      size: 22,
                                      color: Colors.white70,
                                    ),
                                    //decoration: BoxDecoration(border: Border(bottom: BorderSide(width: 1,color: Colors.black26))),
                                    // decoration: BoxDecoration(
                                    //     boxShadow: [
                                    //       BoxShadow(offset: Offset(1,1),
                                    //           blurRadius: 5,
                                    //           color: Colors.white
                                    //       )
                                    //     ],
                                    //     borderRadius: BorderRadius.circular(10)
                                    // ),
                                  ),
                            Container(
                              //color: Colors.orange,
                              //alignment: Alignment.center,
                              width: 75,
                              height: 25,
                              child: Text(
                                e.name.toString(),
                                textAlign: TextAlign.center,
                              ),
                            )
                          ],
                        ),
                      ),
                    )
                    .toList()),
          ),
        ),

        !context.read<LoginProvider>().isLogin?_index == 0?
         Positioned(
            bottom: 70,
            child: Padding(
              padding: EdgeInsets.only(left: 0, right: 18),
              child: Container(
                alignment: Alignment.center,
                width: MediaQuery.of(context).size.width,
                height: 50,
                //decoration: BoxDecoration(borderRadius: BorderRadius.circular(10),color: Colors.green,),
                child: Padding(
                  padding: EdgeInsets.only(left: 7, right: 7),
                  child: Container(
                    width: MediaQuery.of(context).size.width,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10),
                      color: Colors.black,
                    ),
                    height: 50,
                    alignment: Alignment.center,
                    child: Padding(
                      padding: EdgeInsets.only(left: 10, right: 10),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("登录,开启你的3D商品之旅"),
                          InkWell(
                            onTap: (){
                              print("点击了登录....");
                              Navigator.of(context).pushNamed("registertwo");
                            },
                            child: Container(
                              alignment: Alignment.center,
                              width: 50,
                              height: 25,
                              child: Text(
                                "登录",
                                style:
                                    TextStyle(fontSize: 14, color: Colors.black),
                              ),
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(16),
                                  color: Colors.amberAccent),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            )):Text(""):Text(""),
        //Positioned(bottom: 50,child: Center(child: Text("----"+(!phone).toString()+"----"+(_index == 0).toString()),)),
      ],
    ));
  }
}
